package cn.com.ejiakanghu.dto;

import cn.com.ejiakanghu.goods.dto.GoodsPriceInfo;
import cn.com.ejiakanghu.goods.dto.GoodsTag;
import org.apache.commons.lang.StringUtils;
import org.linlinjava.litemall.core.util.JacksonUtil;
import org.linlinjava.litemall.db.domain.LitemallGoods;

import java.util.ArrayList;
import java.util.List;

/**
 * @author houzb
 * @Description
 * @create 2021-04-14 21:21
 */
public class SkuGoodsData {
    /**
     * 商品id
     */
    private int id;
    /**
     * 商品名称
     */
    private String name;
    /**
     * 商品主图URL，图片宽高尺寸比例:320*320
     */
    private String main_image;
    /**
     * 商品类型
     */
    private String type;

    /**
     * 商品标签列表
     */
    private List<GoodsTag> tags;

    /**
     * 商品价格信息
     */
    private GoodsPriceInfo priceInfo;
    /**
     * 商品是否已下架
     */
    private int is_offline;
    /**
     * 商品是否已失效,商品可以看，但不能购买
     */
    private int is_invalid;
    /**
     * 商品是否不支持购买，商品可以看但不能买
     */
    private int is_disabled;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getMain_image() {
        return main_image;
    }

    public void setMain_image(String main_image) {
        this.main_image = main_image;
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public List<GoodsTag> getTags() {
        return tags;
    }

    public void setTags(List<GoodsTag> tags) {
        this.tags = tags;
    }

    public GoodsPriceInfo getPriceInfo() {
        return priceInfo;
    }

    public void setPriceInfo(GoodsPriceInfo priceInfo) {
        this.priceInfo = priceInfo;
    }

    public int getIs_offline() {
        return is_offline;
    }

    public void setIs_offline(int is_offline) {
        this.is_offline = is_offline;
    }

    public int getIs_invalid() {
        return is_invalid;
    }

    public void setIs_invalid(int is_invalid) {
        this.is_invalid = is_invalid;
    }

    public int getIs_disabled() {
        return is_disabled;
    }

    public void setIs_disabled(int is_disabled) {
        this.is_disabled = is_disabled;
    }

    public void init(LitemallGoods goods) {
        this.id = goods.getId();
        this.name = goods.getGoodsSn();
        this.main_image = goods.getPicUrl();
        String gTags = goods.getTags();
        this.tags = StringUtils.isNotBlank(gTags) ? JacksonUtil.gson.fromJson(gTags, List.class) : new ArrayList<>();
        this.priceInfo = new GoodsPriceInfo(goods);
        this.is_offline = goods.getIsOnSale() ? 0 : 1;
        //TODO 商品是否不支持购买，商品可以看但不能买
        this.is_disabled = 0 ;
        //TODO 商品是否已失效,商品可以看，但不能购买
        this.is_invalid = 0;
        //TODO 商品类型
        this.type = "";
    }

}
